﻿@using System.Data
@using System.Data.SqlClient
@using ZoomLa.Common
@using ZoomLa.BLL
@using ZoomLa.Model
@model ZoomLa.Model.M_Ask
@{
    Layout = "~/Views/Shared/_ask.cshtml";
    DataTable ansDt = (DataTable)ViewBag.ansDt;
}
@functions{
    B_GuestAnswer ansBll = new B_GuestAnswer();
    B_Ask askBll = new B_Ask();
    B_User buser = new B_User();
    protected string getstatus(string status)
    {
        switch (status)
        {
            case "2": return "推荐答案";
            case "1": return "";
            default: return "";
        }
    }
    public DataTable GetDt(string Aid, string Mid)
    {
        M_Ask askMod = askBll.SelReturnModel(DataConverter.CLng(Mid));
        SqlParameter[] sp1 = new SqlParameter[] { new SqlParameter("@id", Aid) };
        return ansBll.Sel(" supplymentid=@id And Userid=" + askMod.UserId, "", sp1);
    }
    public DataTable GetDt2(string Aid, string Mid)
    {
        DataTable dt = askBll.Sel(" ID=" + Mid, "", null);
        SqlParameter[] sp2 = new SqlParameter[] { new SqlParameter("@id", Aid) };
        return ansBll.Sel(" supplymentid=@id And Userid=" + dt.Rows[0]["Userid"], "", sp2);
    }
    protected string getstyle()
    {
        if (buser.CheckLogin())
        {
            return "";
        }
        else return "display:none";
    }
    protected string getstyles()
    {
        if (buser.CheckLogin())
        {
            return "display:none";
        }
        else return "";
    }
    public string GetUserName()
    {
        return buser.GetLogin().UserName;
    }
}
@section head{
    <title>我的提问-@(Call.SiteName)问答</title>
    <script type="text/javascript" src="/Plugins/Ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="/Plugins/Ueditor/ueditor.all.min.js"></script>
}
@section content{
    <div class="container">
        <ol class="breadcrumb">
            <li>您的位置：<a href="/">网站首页</a></li>
            <li><a href="/Ask">问答中心</a></li>
            <li><a href="MyAskList">我的提问</a></li>
            <li class="active">互动详情</li>
        </ol>
        <div class="ask_detial">
            <div class="ask_detial_t"><span>提问问题</span><div class="clearfix"></div></div>
            <div class="ask_detial_tc">
                <ul class="list-unstyled" style="padding:10px;margin:0;">
                    <li>
                        <span>问题内容：</span>@Model.Qcontent <span class="pull-right">
                            <a href="javascript:;" onclick="LikeQue();">
                                <span class="fa fa-star"></span> 收藏
                            </a>
                        </span>
                    </li>
                    <li><span>提问用户：</span>@MvcHtmlString.Create(Model.IsNi == 1 ? "匿名" : "<a href='javascript:;'>" + Model.UserName + "</a>")</li>
                    <li><span>提问日期：</span>@Model.AddTime.ToString("yyyy/MM/dd HH:mm")</li>
                </ul>
            </div>
            <div class="ask_detial_t"><span>补充问题</span><div class="clearfix"></div></div>
            <div class="ask_detial_tc">
                <div style="padding:10px;">@MvcHtmlString.Create(Model.Supplyment)</div>
                <form method="post" action="@MVCHelper.GetAction("/Ask/Supple",Request)">
                    <div class="asl_detial_tb" style="margin-top:0;">
                        <textarea id="Txtsupment" name="Txtsupment" data-type="normal" style="min-height:200px;width:100%;">@Model.Supplyment</textarea>
                        <input type="submit" class="btn btn-success" style="margin:5px;" value="提交" />
                    </div>
                </form>
            </div>

            <div class="ask_detial_t"><span>问题回答</span> <i style="color:#999;">[自己发表的问题不能答复]</i><div class="clearfix"></div></div>
            <div class="ask_detial_th">
                <div style="min-height:50px;">
                    @foreach (DataRow dr in ansDt.Rows)
                    {
                        <div class="ask_detial_tl">
                            <div class="ask_detial_tlt">
                                <span class="pull-right">@DataConverter.CDate(dr["AddTime"]).ToString("yyyy-MM-dd")</span>
                                @MvcHtmlString.Create(dr["IsNi"].ToString() == "1" ? "匿名" : "<a href='/ShowList?id=" + dr["UserID"] + "' target='_blank'>" + dr["UserName"] + "</a>")
                            </div>
                            <div class="ask_detial_tlc">
                                <div class="ask_detial_tlch"><span class="ask_detial_hui">回答：</span>@dr["Content"]</div>
                                @foreach (DataRow row in GetDt(dr["ID"].ToString(), Request["ID"]).Rows)
                                {
                                    <div>
                                        <div><span class="ask_detial_zhui">追问：</span>@dr["Content"]</div>
                                        @foreach (DataRow row2 in GetDt2(row["ID"].ToString(), Request["ID"]).Rows)
                                        {
                                            <div>@row2["Content"]</div>
                                        }
                                    </div>
                                }
                                <div class="ask_detial_tui">
                                    <div>@getstatus(dr["Status"].ToString())</div>
                                    @if (Model.Status != 2)
                                    {
                                        <input type="button" class="btn btn-warning btn-sm" value="继续追问" onclick="supplyment(@dr["ID"]);" />
                                                    <a href="/Ask/Recomand?Aid=@dr["ID"]&ID=@Request["ID"]" id="recommand" class="btn btn-success btn-sm pull-right" onclick="return confirm('你确认推荐吗?');">推荐为满意答案</a>
                                    }
                                </div><div class="clearfix"></div>
                            </div>
                        </div>
                    }
                    <div style="display:none;" id="divSupplyment">
                        <form method="post" action="@MVCHelper.GetAction("/Ask/SuppleAsk",Request)">
                            <input type="hidden" id="Rid" name="Rid" />
                            <textarea id="txtSupplyment" name="txtSupplyment" class="form-control" rows="6"></textarea>
                            <input type="submit" value="提交追问" class="btn btn-default" />
                        </form>
                    </div>
                </div>
            </div>
            <div id="main" class="rg_inout">
            </div>
        </div>
    </div>
    <input type="hidden" id="hfstatus" name="hfstatus" />
    @MvcHtmlString.Create(Call.GetUEditor("Txtsupment", 4))
}
@section script{
    <script type="text/javascript" src="/JS/Modal/APIResult.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#top_nav_ul li[title='在线提问']").addClass("active");
        })
        function show() {
            var div = document.getElementById("show");
            if (div.style.display == "none") {
                div.style.display = "block";
            }
            // else {div.style.display = "none";}
        }
        function ViewQes() {
            if ($("#viewQ").css("display") == "none")
                $("#viewQ").css("display", "");
            else
                $("#viewQ").css("display", "none");
        }
        function supplyment(id) {
            document.getElementById("Rid").value = id;
            var div = document.getElementById("divSupplyment");
            if (div.style.display == "none") {
                div.style.display = "block";
            }
            else {
                div.style.display = "none";
            }
        }
        function Recommend_click(id) {
            document.getElementById("hfstatus").value = id;

        }
        function CheckDirty() {
            var TxtTTitle = document.getElementById("TxtTTitle").value;
            var TxtValidateCode = document.getElementById("TxtValidateCode").value;

            if (value == "" || TxtTTitle == "" || TxtValidateCode == "") {
                if (value == "") {
                    var obj = document.getElementById("RequiredFieldValidator1");
                    obj.innerHTML = "<font color='red'>内容不能为空！</font>";
                }
                else {
                    var obj = document.getElementById("RequiredFieldValidator1");
                    obj.innerHTML = "";
                }
                if (TxtTTitle == "") {
                    var obj2 = document.getElementById("RequiredFieldValidator2");
                    obj2.innerHTML = "<font color='red'>留言标题不能为空！</font>";
                }
                else {
                    var obj2 = document.getElementById("RequiredFieldValidator2");
                    obj2.innerHTML = "";
                }
                if (TxtValidateCode == "") {
                    var obj3 = document.getElementById("sp1");
                    obj3.innerHTML = "<font color='red'>验证码不能为空！</font>";
                } else {
                    var obj3 = document.getElementById("sp1");
                    obj3.innerHTML = "";
                }
                return false;
            }
            else {
                var obj = document.getElementById("RequiredFieldValidator1");
                obj.innerHTML = "";
                var obj2 = document.getElementById("RequiredFieldValidator2");
                obj2.innerHTML = "";
                var obj3 = document.getElementById("sp1");
                obj3.innerHTML = "";
                document.getElementById("EBtnSubmit2").click();
            }
        }
        //收藏问题
        function LikeQue() {
            $.post('/API/mod/collect.ashx', { action: "add", favurl: "@Request.RawUrl", infoid: "@Request["ID"]", type: 4, title: $("#question").text() }, function (data) {
                var model = JSON.parse(data);
                if (APIResult.isok(model)) {
                    alert("收藏成功!");
                } else {
                    alert("收藏失败!原因:" + model.retmsg);
                }
            });
        }
    </script>
}